import pandas as pd
import json
import numpy as np
import sys
sys.path.append("..")
from 查找没用的图片 import listDir

def readFile(x):
    with open(f'/Users/wangshuguan/Desktop/辽宁/辽宁_{x}.txt') as f:
        str = f.read()
        j = json.loads(str)
        return j
    
def saveAllData():
    allSourceFiles = listDir('/Users/wangshuguan/Desktop/辽宁',extensions=["txt"],reuslts = [])
    dataFrames = []
    for x in range(1,len(allSourceFiles)+1):
        numpArr = np.array(readFile(x)[0:21])
        if len(allSourceFiles) == x:
            numpArr = np.array(readFile(x)[0:18])
        if len(numpArr)>0:
            pdArr = pd.DataFrame(numpArr[1:],columns=list(numpArr[0]))
            dataFrames.append(pdArr)
        else:
            print(x)
    allframes = pd.concat(dataFrames)
    
#     def save(filename, contents):
#           fh = open(filename, 'w', encoding='utf-8')
#           fh.write(contents)
#           fh.close()
#     save(f'/Users/wangshuguan/辽宁省全部数据.txt', allframes.to_json(orient='records',force_ascii=False))
#     

    with pd.ExcelWriter('/Users/wangshuguan/Desktop/辽宁列表.xls') as writer:
            allframes.to_excel(writer, sheet_name='数据统计')
        
# saveAllData()
        
# companys = [x['企业名称'] for x in datas]
# for x in companys:
# #     if x.find("公司") == -1 and  x.find("局") == -1 and  x.find("网") == -1 and  x.find("中心") == -1 and  x.find("院") == -1 and  x.find("平台") == -1 and  x.find("所") == -1 and  x.find("队") == -1 and  x.find("室") == -1 and  x.find("处") == -1 and  x.find("站") == -1 and  x.find("场") == -1 and  x.find("城") == -1 and  x.find("部") == -1 and  x.find("厂") == -1:
#     print(x)





df = pd.read_excel("/Users/wangshuguan/Desktop/辽宁列表.xls")
print(len(df.企业名称.unique()))